import { serve } from "h3";
import app from "./app.ts";
import { onExit } from "./helper/shutdown.ts";
import { connect, closeAll } from "./helper/mongo.ts";

const server = serve(app, {
  port: Number(process.env.PORT || 3000),
  hostname: "127.0.0.1",
});

// 连接数据库
connect(process.env.DATABASE_URL || "");

onExit(async () => {
  await server.close();
  closeAll();
  console.log("server closed!");
});
